<?php
/**
 * @name /www/unit-tests/multi-level-dialogs.php
 * @author Michael Foss <michael@mikefoss.com>
 * @version 2011.03.26
 * 
 * This proves whether or not you can use multi-level dialogs.
 */

// Sets up configuration settings and includes libraries.
require_once('_ini.php');

function DefineHeader() {
?><style type="text/css">
  code {
    font: bold 10pt 'Courier New';
    color: #666;
    background-color: #CCC;
    border: 3px solid #666;
    padding: 4px 6px;
    margin: 10px 20px;
    display: block;
  }
  form, ul, ol {
    margin: 0px 20px;
  }
  a#Back {
    float: right;
    margin: 10px;
    padding: 4px 6px;
    border: 1px solid #666;
    background-color: #CCC;
  }
</style>
<script type="text/javascript">
  $(function() {
    // Find dialogs
    var $dialogs = [
      $('.Level1'),
      $('.Level2'),
      $('.Level3')
    ];

    // Init
    for (i = 0; i < 3; i++)
      $dialogs[i]
        .dialog({
          autoOpen: false,
          modal: true,
          buttons: {
            Close: function() {
              $(this).dialog('close');
            }
          }
        });

    // Level 0
    $('input[type=button]:eq(0)')
      .button({
        label: 'Open 1'
      })
      .click(function() {
        $('.Level1').dialog('open');
      });
    $('input[type=button]:eq(1)')
      .button({
        label: 'Open 2'
      })
      .click(function() {
        $('.Level2').dialog('open');
      });
    $('input[type=button]:eq(2)')
      .button({
        label: 'Open 3'
      })
      .click(function() {
        $('.Level3').dialog('open');
      });

    // Level 1
    $dialogs[0]
      .find('input[type=button]')
      .button({
        label: 'Open 2'
      })
      .click(function() {
        $('.Level2').dialog('open');
      });

    // Level 2
    $dialogs[1]
      .find('input[type=button]')
      .button({
        label: 'Open 3'
      })
      .click(function() {
        $('.Level3').dialog('open');
      });

    // Level 3
    $dialogs[2]
      .find('input[type=button]')
      .button({
        label: 'Close All'
      })
      .click(function() {
        for (j = 3; j > 0; j--)
          $('.Level' + j).dialog('close');
      });
  });
</script>
<?
}

/**
 * Defines page content.
 *
 */
function DefineContent() {
?><h1>Multi-Level Dialogs</h1>
<a id="Back" href="../unit-tests/index.php">Back to Unit Tests</a>
<p>
  <input type="button" />
  <input type="button" />
  <input type="button" />
</p>
<div class="Level1" style="display: none;">
  <p>
    Dialog level 1
  </p>
  <input type="button" />
</div>
<div class="Level2" style="display: none;">
  <p>
    Dialog level 2
  </p>
  <input type="button" />
</div>
<div class="Level3" style="display: none;">
  <p>
    Dialog level 3
  </p>
  <input type="button" />
</div>
<?
}

// Launches the page; without this, nothing happens.
require_once('_loader.php');